package net.xiangcaowuyu.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import net.xiangcaowuyu.springcloud.service.PaymentFeignHystrixService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 博客：https://www.xiangcaowuyu.net
 * Description:
 *
 * @Author: 香草物语
 * DateTime: 2021-07-24 17:00
 */
@RestController
@RequestMapping("/consumer")
@Slf4j
//@DefaultProperties(defaultFallback = "payment_global_callback")
public class OrderFeignHystrixController {

    @Resource
    private PaymentFeignHystrixService paymentFeignHystrixService;

    @GetMapping("/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable Integer id) {
        return paymentFeignHystrixService.paymentInfo_OK(id);
    }

    //    @HystrixCommand(fallbackMethod = "paymentInfo_TimeoutHandler",
//            commandProperties = {
//                    @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1500")
//            })
//    @HystrixCommand
    @GetMapping("/payment/hystrix/timeout/{id}")
    public String paymentInfo_Timeout(@PathVariable Integer id) {
        return paymentFeignHystrixService.paymentInfo_Timeout(id);
    }

    @GetMapping("/payment/zipkin")
    public String zipkin() {
        return paymentFeignHystrixService.zipkin();
    }

    public String paymentInfo_TimeoutHandler(Integer id) {
        return "我是消费者80，线程池：" + Thread.currentThread().getName() + " paymentInfo_TimeoutHandler,id:" + id + "\t/(ㄒoㄒ)/~~";
    }

    public String payment_global_callback() {
        return "全局异常降级";
    }

}
